package com.ceshiren.springstudy.controller;

import com.alibaba.fastjson.JSONObject;
import com.ceshiren.springstudy.dto.UserDto;
import com.ceshiren.springstudy.dto.UserXmlDto;
import com.ceshiren.springstudy.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author gaoxiaoqi
 * @date 2024/6/4 22:43
 * @description
 */
@RestController
@Api(tags = "BasePostController: 用户controller类post请求")
public class BasePostController {

    @Autowired
    @Qualifier("userImp")
    UserService userService;

    @Value("${ceshi.param1}")
    private String param1;

    @PostMapping(value = "/login", produces = "application/json")
    public String postMethodDemo1(@RequestBody UserDto userDto) {
        System.out.println(userDto.toString()+"sdfsdkfjksadklfjk");
        System.out.println("param1：" + param1);
        return userService.postMethodDemo1(userDto);
//        return userDto.toString();
    }


    @PostMapping(value = "/{module}/register", produces = "application/json")
    @ApiOperation("用户注册方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "desc",value = "描述说明"),
            @ApiImplicitParam(name = "module",value = "请求路径"),
            @ApiImplicitParam(name = "age",value = "用户年龄")
    })
    public String registerAndParam(@RequestBody UserDto userDto, @PathVariable String module,
                                   @RequestParam String desc, @RequestParam String age) {
        return "用户名：" + userDto.getUsername() + "密码：" + userDto.getPassword() + " module：" +
                module + " desc：" + desc + " age：" + age;
    }


    @PostMapping(value = "/{module}/registerXml", produces = MediaType.APPLICATION_ATOM_XML_VALUE)
    public String registerXmlAndParam(@RequestBody UserXmlDto userDto, @PathVariable String module,
                                      @RequestParam String desc, @RequestParam String age) {
        return "用户名：" + userDto.getUsername() + "密码：" + userDto.getPassword() + " module：" +
                module + " desc：" + desc + " age：" + age;
    }

}
